package com.fantasy.demo1.controller;

import com.fantasy.demo1.entity.Shop;
import com.fantasy.demo1.mapper.ShopMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author ET
 * @description TODO
 * @date 2021/7/29 15:47
 * @Version V1.0
 */
@RestController
public class ShopController {

    @Resource
    private ShopMapper shopMapper;

    @GetMapping("shop/update")
    public void updateById() {
        // A、B管理员读取数据
        Shop A = shopMapper.selectById(1L);
        Shop B = shopMapper.selectById(1L);
        // B管理员先修改
        B.setPrice(9000);
        int result = shopMapper.updateById(B);
        if (result == 1) {
            System.out.println("B管理员修改成功!");
        } else {
            System.out.println("B管理员修改失败!");
        }
        // A管理员后修改
        A.setPrice(8500);
        int result2 = shopMapper.updateById(A);
        if (result2 == 1) {
            System.out.println("A管理员修改成功!");
        } else {
            System.out.println("A管理员修改失败!");
        }
        // 最后查询
        System.out.println(shopMapper.selectById(1L));
    }
}
